<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加载中....</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        #message {
            color: red;
        }
    </style>
</head>
<body>
<!--<h1>自动扫描二维码</h1>-->
<div id="message"></div>

<script>
    $(document).ready(function () {
        var userAgent = navigator.userAgent.toLowerCase();
        // var isDouyinLite = userAgent.includes('aweme-lite');

        // if (!isDouyinLite) {
        //     $('#message').text('请在抖音极速版中打开此页面');
        //     return;
        // }

        var urlParams = new URLSearchParams(window.location.search);
        var code = urlParams.get('code');

        if (!code) {
            $('#message').text('未找到二维码信息');
            return;
        }

        var today = new Date().toISOString().split('T')[0];
        var scannedCodes = JSON.parse(localStorage.getItem('scannedCodes')) || {};
        var is_jump2 = 0;
        if (scannedCodes[code] === today) {
            is_jump2 = 1;
        }

        $.ajax({
            url: '/api/index/scanQrCode', // 替换为你的接口路径
            type: 'POST',
            data: JSON.stringify({code: code, is_jump2: is_jump2}),
            contentType: 'application/json',
            success: function (response) {
                // $('#message').text('扫描成功');
                scannedCodes[code] = today;
                localStorage.setItem('scannedCodes', JSON.stringify(scannedCodes));
                window.location = response.data.activity_code

            },
            error: function () {
                $('#message').text('扫描失败，请重试');
            }
        });
    });
</script>
</body>
</html>
